

<html>
<body>
<?php
include('config.php');

if(isset($_GET['table'], $_GET['rideName'],$_SESSION['username']) and !empty($_GET['table']) and !empty($_GET['rideName'])){

        //recuperation des données passées
        $userId = $_SESSION['userid'];
        $username = $_SESSION['username'];
        $rideName = mysql_real_escape_string($_GET['rideName']);
        $array = mysql_real_escape_string($_GET['table']);
		
        $insertRide = 'insert into ride(creator,name,creation_date) values('.$userId.',"'.$rideName.'","'.date('Y-m-d').'")';
        mysql_query($insertRide);
        $idRide = mysql_insert_id();

        //traitement sur le tableau
        $array = explode(',(',$array);
       
        $i = 0;
        foreach($array as $coordonnes){
					$coordonnes =  str_replace("(", "", $coordonnes);
					$coordonnes =  str_replace(")", "", $coordonnes);
					list($latitude, $longitude) = explode(',',$coordonnes);
										     
					$insertPoint = "insert into point(latitude,longitude,numSeq,ride) values ($latitude,$longitude,$i,$idRide)" or die ("erreur d'insertion des points");
					mysql_query($insertPoint);
					$i = $i+1;
        }
       
}
?>
<script type="text/javascript">
alert("Votre parcours a ete enregistre");
window.location.replace("creer_trace.php");
</script>
</body>
</html>

